package typeconvert;

import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

public class CustomMysqlTypeConvert extends MySqlTypeConvert {
    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {

//            if (fieldType.toLowerCase().contains("tinyint")) {
//                return DbColumnType.BOOLEAN;
//            }

        if (fieldType.equalsIgnoreCase("datetime")
                || fieldType.equalsIgnoreCase("datetime2")
                || fieldType.equalsIgnoreCase("date")) {
            return DbColumnType.DATE;
        }

        System.out.println("fieldType:" + fieldType);

        //无符号整型
        if (fieldType.startsWith("int") && fieldType.endsWith("unsigned")) {
            return DbColumnType.LONG;
        }

        if (fieldType.startsWith("decimal")) {
            return DbColumnType.BIG_DECIMAL;
        }

        return super.processTypeConvert(globalConfig, fieldType);
    }
}